home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Clickable URL Class
- */
-
- #include "include/config.h"
-
- #include <string.h>
-
- #include "include/mui.h"
- #include <proto/graphics.h>
- #include <proto/openurl.h>
-
- #include "include/url.h"
-
- struct Library *OpenURLBase;
-
- ULONG url_new(struct IClass *cl, Object *obj, struct opSet *msg);
- ULONG url_setup(struct IClass *cl, Object *obj, Msg msg);
- ULONG url_minmax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg);
- ULONG url_draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg);
- ULONG url_cleanup(struct IClass *cl, Object *obj, Msg msg);
- ULONG url_clicked(struct IClass *cl, Object *obj, Msg msg);
-
-
- MUIF url_dispatch(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)
- {
- switch(msg->MethodID) {
- case OM_NEW: return(url_new(cl,obj,(APTR)msg));
- case MUIM_Setup: return(url_setup(cl,obj,(APTR)msg));
- case MUIM_AskMinMax: return(url_minmax(cl,obj,(APTR)msg));
- case MUIM_Draw: return(url_draw(cl,obj,(APTR)msg));
- case MUIM_Cleanup: return(url_cleanup(cl,obj,(APTR)msg));
- case URL_CLICKED: return(url_clicked(cl,obj,(APTR)msg));
- }
- return(DoSuperMethodA(cl,obj,msg));
- }
-
-
- ULONG url_new(struct IClass *cl, Object *obj, struct opSet *msg)
- {
- struct urldata *data;
- char *name, *href;
-
- name = (char *)GetTagData(URL_NAME,0,msg->ops_AttrList);
- href = (char *)GetTagData(URL_HREF,0,msg->ops_AttrList);
-
- obj = (Object *)DoSuperNew(cl,obj,
- MUIA_Font, MUIV_Font_Button,
- MUIA_ShowSelState, FALSE,
- MUIA_InputMode, MUIV_InputMode_RelVerify,
- /* MUIA_ShortHelp, help, */
- TAG_MORE, msg->ops_AttrList);
-
- if(!obj) return(NULL);
-
- data = INST_DATA(cl,obj);
- data->name = name;
- data->href = href;
- data->len = strlen(name);
- data->color = -1;
-
- DoMethod(obj,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,URL_CLICKED);
- return((ULONG)obj);
- }
-
-
- ULONG url_setup(struct IClass *cl, Object *obj, Msg msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
-
- if (!DoSuperMethodA(cl,obj,msg))
- return(FALSE);
-
- data->color = ObtainBestPen(_screen(obj)->ViewPort.ColorMap,0,0,0,OBP_Precision,PRECISION_GUI,TAG_DONE);
-
- return(TRUE);
- }
-
-
- ULONG url_minmax(struct IClass *cl, Object *obj, struct MUIP_AskMinMax *msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
- int x,y;
-
- DoSuperMethodA(cl,obj,(APTR)msg);
-
- x = _font(obj)->tf_XSize * data->len;
- y = _font(obj)->tf_YSize;
-
- msg->MinMaxInfo->MinWidth += x;
- msg->MinMaxInfo->DefWidth += x + (x/10);
- msg->MinMaxInfo->MaxWidth += MUI_MAXMAX;
- msg->MinMaxInfo->MinHeight += y;
- msg->MinMaxInfo->DefHeight += y;
- msg->MinMaxInfo->MaxHeight += y;
-
- return(0);
- }
-
-
- ULONG url_draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
- int x,y,i;
-
- DoSuperMethodA(cl,obj,(APTR)msg);
- if(!(msg->flags & MADF_DRAWOBJECT)) return(0);
-
- SetFont(_rp(obj),_font(obj));
-
- if(!data->pixlen) data->pixlen=TextLength(_rp(obj),data->name,data->len);
- x = _mleft(obj) + ( (_mwidth(obj) - data->pixlen) / 2);
- y = _mtop(obj) + _font(obj)->tf_Baseline + ( (_mheight(obj) - _font(obj)->tf_YSize) / 2 );
-
- Move(_rp(obj),x,y);
- if(data->color != -1) SetAPen(_rp(obj),data->color); else SetAPen(_rp(obj),1);
- Text(_rp(obj),data->name,data->len);
-
- for (i=x; i<=x+data->pixlen; i+=4) {
- Move(_rp(obj), i, y+3);
- Draw(_rp(obj), i+1, y+3);
- }
-
- return(0);
- }
-
-
- ULONG url_cleanup(struct IClass *cl, Object *obj, Msg msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
-
- if(data->color != -1) ReleasePen(_screen(obj)->ViewPort.ColorMap,data->color);
-
- return(DoSuperMethodA(cl,obj,msg));
- }
-
-
- ULONG url_clicked(struct IClass *cl, Object *obj, Msg msg)
- {
- struct urldata *data = INST_DATA(cl,obj);
-
- OpenURLBase = OpenLibrary("openurl.library", 1);
- if (!OpenURLBase) return(0);
- URL_Open(data->href, TAG_DONE);
- CloseLibrary(OpenURLBase);
- return(0);
- }
-